<template>
    <view class="map_wrap">
        <map id="mapSelected" style="width: 690rpx; height: 300px; margin-left: 30rpx;" :latitude="latitude" :longitude="longitude" :markers="covers" :controls="controls" :scale="18" @controltap="controltap" @tap="clickMap" 
        @regionchange="regionchange">
        </map>
        
		<view class="mform">
			<view class="item">
				<view class="t">当前地址：</view>
				<view class="m">{{address}}</view>
			</view>
			<view class="item">
				<view class="t">推荐地址：</view>
				<view class="m">{{address_info}}</view>
			</view>
		</view>
        
        <!-- 保存按钮这里具体保存事件我没写，根据实际需要调用后台保存地址即可 -->
		<view class="btnbox">
			<button class="btn" @click="saveAddress()" style="width:85%;">保存</button>
		</view>
    </view>
</template>


<script>
	export default {
		components: {
			name: '',
			address: '',
			latitude: '',
			longitude: '',
		},
		data() {
			return {
						title: 'map',
						latitude: 39.909,// 默认纬度
						longitude: 116.39742,// 默认经度(北京天安门)
						covers: [{
							id: 110, 
							latitude: 39.909,
							longitude: 116.39742,
							iconPath: '	https://hellouniapp.dcloud.net.cn/static/location.png',
							width: "20",
							height: "20"
						}],
						controls: [{ // 控件
							id: 99,
							position: { // 控件位置
								left: 160,
								top: 120
							},
							iconPath: 'https://hellouniapp.dcloud.net.cn/static/location.png' // 控件图标
						}],
						address_info :"",
						address_info_recomd:"",
						address :""
					}
		},
		// 页面加载
		onLoad(e) {
			uni.hideTabBar(); //不让底部显示tab选项
			this.getData();
		},
		// 页面显示
		onShow() {

		},
		// 方法
		methods: {
			clickSite() {
				// 所在地址
				var _this = this;
				wx.chooseLocation({
					success: function(res) {
						var name = res.name
						var address = res.address;
						var latitude = res.latitude;
						var longitude = res.longitude;
						_this.form.city = res.address;
						_this.form.city1 = res.address
						console.log(name, address, latitude, longitude, '158');
					},
					complete(res) {
						// 点击确定完成以后-进入对应的页面
						console.log(res, '161');

						if (res.errMsg == 'chooseLocation:fail cancel') {
							console.log(111)
						} else {

						}
					}
				})
			},
			//获取数据
			getData() {
				var _this = this;
				wx.chooseLocation({
					success: function(res) {
						var name = res.name
						var address = res.address
						var latitude = res.latitude
						var longitude = res.longitude
						
						console.log(name,address,latitude,longitude,'58')
					},
					complete(r) {
						// 点击确定完成以后-进入对应的页面
						console.log(r,'71');
					}
				})

			},
			//获取列表数据
			getListData() {
				this.$.ajax("POST", "/xxxxx/xxxxx", {
					page: this.pageNum,
				}, (res) => {
					if (res) {
						if (this.pageNum == 1) {
							this.list = res.data
						} else {
							this.list = this.list.concat(res.data)
							if (res.data.length === 0) {
								this.pageNum--
							}
						}
					}
					uni.stopPullDownRefresh()
				});
			}
		},
		// 计算属性
		computed: {

		},
		// 侦听器
		watch: {

		},
		// 页面隐藏
		onHide() {

		},
		// 页面卸载
		onUnload() {

		},
		// 触发下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1
			// this.getListData()
		},
		// 页面上拉触底事件的处理函数
		onReachBottom() {
			this.pageNum++
			// this.getListData()
		},
	}
</script>

<style lang="scss" scoped>
	.address {}
</style>

